package com.shroo8.footballblog.controllers.api;

import java.util.Locale;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shroo8.footballblog.bo.api.CreateCommentBo;
import com.shroo8.footballblog.dto.api.CommentDto;
import com.shroo8.footballblog.dto.api.UserDto;

@Controller
public class CreateCommentController {
	private static final Logger logger = LoggerFactory.getLogger(CreateCommentController.class);
	
	@Resource(name="createCommentBo")
	CreateCommentBo createCommentBo;
	
	@RequestMapping(value = "/comments", method = RequestMethod.POST)
	public @ResponseBody String createComment(Locale locale, @RequestParam("articleId") String articleId, 
			@RequestParam("userId") String userId, @RequestParam("commentText") String commentText) {

		logger.info("Welcome to createComment! The client locale is {}.", locale);
		logger.info("articleId: " + articleId);
		
		CommentDto commentDto = new CommentDto();
		UserDto commentor = new UserDto();
		commentDto.setArticleId(articleId);
		commentDto.setCommentText(commentText);
		commentor.setId(userId);
		commentDto.setCommentor(commentor);
		createCommentBo.createComment(commentDto);
		return ""; 
	}

}
